package com.ciwong.epaper.modules.me.ui;

import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.ciwong.epaper.R;
import com.ciwong.epaper.modules.share.QQShareHelper;
import com.ciwong.epaper.widget.ShareQRcodeDialog;
import com.ciwong.mobilelib.i.ViewOnClickListener;
import com.ciwong.mobilelib.ui.BaseActivity;
import com.ciwong.mobilelib.utils.BaseJumpManager;
import com.tencent.connect.common.Constants;

/**
 * 关于界面
 *
 * @author res-qqlin
 * @version ciwong v.2.0 2015/8/10
 * @since ciwong v.2.0
 */
public class AboutActivity extends BaseActivity {
    private TextView aboutDesc;
    private Button mTvShare;
    private ImageView mIvAppicon;
    private ViewGroup aboutAgreement, aboutDeclaration;

    private ViewOnClickListener mViewOnClickListener = new ViewOnClickListener() {
        @Override
        public void avertRepeatOnClick(View v) {
            int id = v.getId();
            if (id == R.id.about_agreement) {
                BaseJumpManager.jumpToBrowser(AboutActivity.this,
                        R.string.go_back, getString(R.string.agreement_use_url), null);
            } else if (id == R.id.about_declaration) {
                BaseJumpManager.jumpToBrowser(AboutActivity.this,
                        R.string.go_back, getString(R.string.agreement_secret_url), null);
            } else if (id == R.id.tv_share) {
                ShareQRcodeDialog shareDialog = new ShareQRcodeDialog(AboutActivity.this);
                shareDialog.show();
            }
        }
    };

    @Override
    protected int setView() {
        return R.layout.activity_about;
    }

    @Override
    protected void findViews() {
        aboutDesc = (TextView) findViewById(R.id.aboutDesc);
        aboutAgreement = (ViewGroup) findViewById(R.id.about_agreement);
        aboutDeclaration = (ViewGroup) findViewById(R.id.about_declaration);
        mTvShare = (Button) findViewById(R.id.tv_share);
        mIvAppicon = (ImageView) findViewById(R.id.iv_app_icon);
    }

    @Override
    protected void initEvent() {
        aboutAgreement.setOnClickListener(mViewOnClickListener);
        aboutDeclaration.setOnClickListener(mViewOnClickListener);
        mTvShare.setOnClickListener(mViewOnClickListener);
    }

    @Override
    protected void init() {
        setValideSource(false);
        setTitleText(R.string.about_us);
        try {
            aboutDesc.setText(getString(R.string.about_desc,
                    getString(R.string.app_name)));
        } catch (Exception e) {
            e.printStackTrace();
        }
//        try {
//            Bitmap bitmap = createQRCodeWithLogo(getString(R.string.download_url), 800,
//                    BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher));
//            mIvAppicon.setImageBitmap(bitmap);
//        } catch (Exception e) {
//
//        }
    }

    @Override
    protected void loadData() {

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == Constants.REQUEST_QQ_SHARE || requestCode == Constants.REQUEST_QZONE_SHARE) {
            QQShareHelper.getInstance().onActivityResultData(requestCode, resultCode, data);
        }
        super.onActivityResult(requestCode, resultCode, data);
    }

}
